package com.cskaoyan.service;

import com.cskaoyan.bean.basebean.BaseParam;
import com.cskaoyan.bean.basebean.BasePageData;
import com.cskaoyan.bean.CouponUser;
import com.cskaoyan.bean.CouponUserExample;
import com.cskaoyan.mapper.CouponUserMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lxy
 * @create 2021-10-19 20:15
 */
@Service
public class CouponUserServiceImpl implements CouponUserService {

    @Autowired
    CouponUserMapper couponUserMapper;

    @Override
    public BasePageData queryUser(Integer couponId, Integer userId, Short status, BaseParam baseParam) {
        PageHelper.startPage(baseParam.getPage(),baseParam.getLimit());
        CouponUserExample example = new CouponUserExample();
        CouponUserExample.Criteria criteria = example.createCriteria();

        if (couponId != null) {
            criteria.andCouponIdEqualTo(couponId);
        }

        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }

        if (status != null) {
            criteria.andStatusEqualTo(status);
        }


        example.setOrderByClause(baseParam.getSort() + " " + baseParam.getOrder());

        List<CouponUser> couponUsers = couponUserMapper.selectByExample(example);

        return BasePageData.ok(couponUsers);
    }
}
